Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
typedarray-pool
Advanced tools
The 'typedarray-pool' npm package provides efficient memory management for typed arrays by reusing and recycling them. This can help reduce garbage collection overhead and improve performance in applications that frequently allocate and deallocate typed arrays.
Allocate a Typed Array
This feature allows you to allocate a new typed array from the pool. The 'mallocFloat32' function allocates a Float32Array of the specified length (10 in this case).
const pool = require('typedarray-pool');
const array = pool.mallocFloat32(10);
Free a Typed Array
This feature allows you to return a typed array back to the pool for reuse. The 'free' function takes the typed array and makes it available for future allocations.
pool.free(array);
Reallocate a Typed Array
This feature allows you to allocate a new typed array with a different size. The 'mallocFloat32' function can be called again with a different length (20 in this case) to get a new array.
const newArray = pool.mallocFloat32(20);
The 'buffer-pool' package provides a similar functionality for managing and reusing Buffer objects. It helps in reducing memory fragmentation and garbage collection overhead by pooling Buffer instances. Unlike 'typedarray-pool', it is specifically designed for Node.js Buffer objects.
The 'array-pool' package offers a general-purpose pool for JavaScript arrays. It allows for efficient reuse of arrays to minimize garbage collection. While 'typedarray-pool' focuses on typed arrays, 'array-pool' is more generic and can be used for any type of JavaScript array.
The 'object-pool' package provides a pooling mechanism for JavaScript objects. It is useful for managing and reusing objects to reduce memory allocation overhead. Although it is not specific to typed arrays, it offers similar benefits in terms of memory management and performance optimization.
A global pool for typed arrays.
var pool = require("typedarray-pool")
//Allocate a buffer with at least 128 floats
var f = pool.malloc(128, "float")
// ... do stuff ...
//When done, release buffer
pool.free(f)
npm install typedarray-pool
var pool = require("typedarray-pool")
pool.malloc(n[, dtype])
Allocates a typed array (or ArrayBuffer) with at least n elements.
n
is the number of elements in the array
dtype
is the data type of the array to allocate. Must be one of:
"uint8"
"uint16"
"uint32"
"int8"
"int16"
"int32"
"float"
"float32"
"double"
"float64"
"arraybuffer"
"data"
"uint8_clamped"
"bigint64"
"biguint64"
"buffer"
Returns A typed array with at least n
elements in it. If dtype
is undefined, an ArrayBuffer is returned.
Note You can avoid the dispatch by directly calling one of the following methods:
pool.mallocUint8
pool.mallocUint16
pool.mallocUint32
pool.mallocInt8
pool.mallocInt16
pool.mallocInt32
pool.mallocFloat
pool.mallocDouble
pool.mallocArrayBuffer
pool.mallocDataView
pool.mallocUint8Clamped
pool.mallocBigInt64
pool.mallocBigUint64
pool.mallocBuffer
pool.free(array)
Returns the array back to the pool.
array
The array object to return to the pool.Note You can speed up the method if you know the type of array before hand by calling one of the following:
pool.freeUint8
pool.freeUint16
pool.freeUint32
pool.freeInt8
pool.freeInt16
pool.freeInt32
pool.freeFloat
pool.freeDouble
pool.freeArrayBuffer
pool.freeDataView
pool.freeUint8Clamped
pool.freeBigInt64
pool.freeBigUint64
pool.freeBuffer
pool.clearCache()
Removes all references to cached arrays. Use this when you are done with the pool to return all the cached memory to the garbage collector.
(c) 2014 Mikola Lysenko. MIT License
FAQs
Reuse typed arrays
The npm package typedarray-pool receives a total of 183,969 weekly downloads. As such, typedarray-pool popularity was classified as popular.
We found that typedarray-pool demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.